<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('用户分配角色')" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <input type="hidden" name="userId" id="userId" th:value="${user.userId}">
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
            	<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">用户名称：</label>
                        <div class="col-sm-8">
                            <input name="userName" class="form-control" type="text" disabled th:value="${user.userName}">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">登录账号：</label>
                        <div class="col-sm-8">
                            <input name="loginName" class="form-control" type="text" disabled th:value="${user.loginName}">
                        </div>
                    </div>
                </div> 
            </div>
           
            <h4 class="form-header h4">分配科室</h4>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="selectDepts()" >
                    <i class="fa fa-plus"></i> 添加科室
                </a>
                <a class="btn btn-warning" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
	    var prefix = ctx + "base/sys/user/authDept";
	    var depts = [[${depts}]]
	    function selectDepts(){
	        $.modal.open("科室列表",ctx+"base/sys/dept/selectDept?userId="+$("#userId").val());
        }
        function deleteUserDept(deptId) {
            $.ajax({
                url: ctx+'base/system/userDept/remove?userId='+$("#userId").val()+"&deptId="+deptId,
                type: 'get',
                success: function (data) {
                    $.table.refresh();
                }
            });
        }
	    $(function() {
		    var options = {
		        url: ctx+"base/system/userDept/list",
		        columns: [
		        {
		            field: 'deptId',
		            title: '科室主键'
		        },
		        {
		            field: 'deptCode',
		            title: '科室编码'
		        },
		        {
		            field: 'deptName',
		            title: '科室名称',
		            sortable: true
		        },
                    {
                        title: '操作',
                        align: 'left',
                        formatter: function(value, row, index) {
                            if (row.parentId != 0) {
                                var actions = [];
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteUserDept(\'' + row.deptId + '\')"><i class="fa fa-trash"></i>删除</a>');
                                return actions.join('');
                            } else {
                                return "";
                            }
                        }
                    }]
		    };
		    $.table.init(options);
		});

    </script>
</body>
</html>